#include <stdio.h>
#include <unistd.h>
#define MAX 2000

int num[MAX];
int sum = 0;
int thread_1_end = 0;
int thread_2_end = 0;
int print_location = 6;

void add_odd(){
    for(int i = 1;i < MAX;i += 2){
        sum += num[i];
        sys_move_cursor(0, print_location);
        printf("> [TASK] The thread_1 add (%d)", num[i]);
    }
    thread_1_end = 1;

    while(1);
}

void add_even(){
    for(int i = 0;i < MAX;i += 2){
        sum += num[i];
        sys_move_cursor(0, print_location);
        printf("> [TASK] The thread_2 add (%d)", num[i]);
    }
    thread_2_end = 1;
    
    while(1);
}

int main(){
    for(int i = 0;i < MAX;i++){
        num[i] = i;
    }
    sys_thread_create(add_odd,1);
    sys_thread_create(add_even,2);

    while(thread_1_end == 0 || thread_2_end == 0);

    sys_move_cursor(0, print_location);
    printf("> [TASK] The final result of sum is (%d)", sum);

    while(1);
}
